<%@ page import="fi.hell.lunchit.Restaurant" %>
<%@ page import="fi.hell.enums.RestaurantSort" %>

<g:set var="locale" value="${grailsApplication.config.locale}" />
<g:if test="${flash.unsupportedSorting}">
    <div class="message">${flash.unsupportedSorting}</div>
</g:if>

<div id="restaurants" class="dialog">
    <h2><g:message code="availableRestaurants" default="Available restaurants" /></h2>
    <div class="sortBar">
      <g:message code="sort" default="Sort" />:
      <g:each in="${RestaurantSort.values()}">
        [
        <a <g:if test="${sort == it}">class="activeSort"</g:if> href="${g.createLink(params:["sort":it.toString().toLowerCase(), "order":(order == 'desc' || !order) ? 'asc' : 'desc'])}">${g.message(code:"restaurant.sort."+it)}</a>
        <g:if test="${sort == it}">
          <g:if test="${order == 'asc'}"><img src="${g.resource(dir:'images', file:'iconAsc.png')}" alt="&Delta;" /></g:if>
          <g:else><img src="${g.resource(dir:'images', file:'iconDesc.png')}" alt="&nabla;" /></g:else>
        </g:if>
        ]
      </g:each>
    </div>
    
    <ul class="restaurantList">
        <g:each var="r" in="${restaurants}">
        	<g:if test="${r.openToday() && (currentRound?.confirmed || !currentRound?.votes?.restaurant?.id?.contains(r.id))}">
            	<li class="controller">
            		<g:if test="${!currentRound?.confirmed && currentVote > 0}">
                		<g:link controller="vote" action="save" id="${r.id}">
                			<img class="restaurantImage" src="${createLink(controller:"image", action:"restaurantLogo", id:r.id)}" />
                        </g:link>
                	</g:if>
                    <g:elseif test="${!currentRound?.confirmed}">
                        <img class="restaurantImage" src="${createLink(controller:"image", action:"restaurantLogo", id:r.id)}" />
                    </g:elseif>
                	<g:else>
                    	<a id="confirmRound" href="${createLink(controller:'vote', action:'finalChoise', id:r?.id)}" onclick="return confirm('${message(code: 'default.button.finalChoise.confirm.message', default: 'Are you sure that your going to eat there??')}');">
							<img class="restaurantImage" src="${createLink(controller:"image", action:"restaurantLogo", id:r?.id)}" />
						</a>
                	</g:else>

                    <br />${r.name}
                    <g:if test="${r.homePage}">
                        <a href="${r.homePage}" target="_blank"><g:message code="restaurant.lunchMenu.label" default="Lunch menu" /></a>
                    </g:if>
                    <br /><g:message code="distance" default="Distance" />: ${r.distance} <g:message code="meters" default="m" />

                    <g:if test="${r.avgPrice() > 0}">
                      <br /><g:message code="avgPrice" default="Average price" />: <g:formatNumber number="${r.avgPrice()/100}" type="currency" locale="${locale}" currencyCode="EUR" />
                    </g:if>
                    <g:else>
                      <br /><g:message code="avgPrice" default="Average price" />: <g:message code="notAvailable" default="Not available" />
                    </g:else>
        		</li>
            </g:if>
        </g:each>
    </ul>
</div>
<div class="clear"></div>